<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理<small>体检上传</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检上传</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="box ordersetting">
                <el-card class="box-card">
                    <div class="boxMain">

                        <div>
                            <el-button style="margin-bottom: 20px;margin-right: 20px" type="primary"
                                       @click="downloadTemplate()">下载体检报告模板
                            </el-button>
                        </div>

                        <div class="filter-container">
                            <el-input placeholder="档案编号/姓名" v-model="pagination.queryString" style="width: 200px;"
                                      class="filter-item"></el-input>
                            <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                        </div>


                        <!--查询后显示的效果-->
                        <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                            <el-table-column type="index" align="center" label="序号"></el-table-column>

                            <el-table-column prop="fileNumber" label="档案编号" align="center"></el-table-column>

                            <el-table-column prop="name" label="姓名" align="center"></el-table-column>

                            <el-table-column label="性别" align="center">
                                <template slot-scope="scope">
                                    <span>{{ scope.row.sex == '1' ? '男' : '女'}}</span>
                                </template>
                            </el-table-column>

                            <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                            <el-table-column prop="remark" label="备注" align="center"></el-table-column>


                            <el-table-column label="操" align="right">
                                <template slot-scope="scope">
                                        <!--  todo 文件上传组件-->
                                        <el-upload class="avatar-uploader"
                                                   action="/medical/upload.do"
                                                   :auto-upload="autoUpload"
                                                   name="imgFile"
                                                   :show-file-list="false"
                                                   :on-success="handleAvatarSuccess"
                                                   :on-error="handleAvatarError"
                                                   :before-upload="beforeAvatarUpload"
                                                   :data="scope.row">
                                            <el-button type="primary">上传体检报告</el-button>
                                        </el-upload>
                                </template>


                            </el-table-column>

                            <el-table-column  align="left">
                                <template slot-scope="scope">
                                    <el-button size="medium" phoneNumber="danger" @click="downloadHealthFrom(scope.row)">
                                        下载体检报告
                                    </el-button>
                                </template>
                            </el-table-column>

                            <el-table-column label="作" align="left">
                                <template slot-scope="scope">
                                    <el-button size="medium" phoneNumber="danger" @click="handleDelete(scope.row)">
                                        删除体检报告
                                    </el-button>
                                </template>
                            </el-table-column>





                        </el-table>


                        <div class="pagination-container">
                            <el-pagination
                                    class="pagiantion"
                                    @current-change="handleCurrentChange"
                                    :current-page="pagination.currentPage"
                                    :page-size="pagination.pageSize"
                                    :total="pagination.total"
                                    layout="total, prev, pager, next, jumper">
                            </el-pagination>
                        </div>
                    </div>
                </el-card>


            </div>
        </div>
    </div>
</div>
</body>

<script>
    new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
        },

        created: function () {//在vue初始化时调用
            // this.initData(null);
            //初始化后自动执行一次查询方法
            this.findPage();
        },
        methods: {


            //上传之前进行文件格式校验
            beforeUpload(file) {
                const isXLS = file.type === 'application/vnd.ms-excel';
                if (isXLS) {
                    return true;
                }
                const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                if (isXLSX) {
                    return true;
                }
                this.$message.error('上传文件只能是xls或者xlsx格式!');
                return false;
            },


            //下载模板文件
            downloadTemplate() {
                window.location.href = "../template/health.xlsx";
            },

            //上传成功提示
            handleAvatarSuccess(response, file) {
                if (response.flag) {
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                } else {
                    this.$message.error(response.message);
                }
                console.log(response, file, fileList);
            },

            //权限不足框架抛出的异常信息
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足    
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },

            //分页查询   使用了钩子函数  页面加载完毕后自动执行一次
            findPage() {
                //定义给后台响应的参数   数据来自于上面的得数
                var param = {
                    currentPage: this.pagination.currentPage,  //页数
                    pageSize: this.pagination.pageSize,        //每页条数
                    queryString: this.pagination.queryString    //查询关键字
                }
                //响应的数据会封装到实体类  PageResult  中
                axios.post("/member/findPage.do", param).then((response) => {
                    //响应回来连个数据  总记录数和当前页结果
                    this.pagination.total = response.data.total;   //要将响应回来的数据上面的数据，用于显示总条数
                    this.dataList = response.data.rows;   //赋值给dataList用于页面展示
                }).catch((response) => {
                    this.showMessage(response)
                });
            },


            //切换页码  参数 currentPage 是切换后的页码
            handleCurrentChange(currentPage) {
                //重新设置页码，将原有的页改成新的页码  显示条数这些不用变
                this.pagination.currentPage = currentPage;
                //调用findPage方法，再次项后端发送数据
                this.findPage();
            },

            //下载
            //下载模板文件
            downloadHealthFrom(row) {

                //发送ajax请求，获取所有体检报告的地址
                axios.get("/medical/downloadHealthFrom.do?id=" + row.id).then((response) => {
                    if (response.data.flag){
                       for (ele of response.data.data){
                           window.location.href = ele;
                       }
                    }else {
                        this.$message.error(response.data.message)
                    }
                })





            },


            // 删除
            handleDelete(row) {
                // 这个 row 是这一行的所有数据  封装为了一个json对象
                //删除的提示信息框
                this.$confirm('警告！！此操作会删除该用户所有体检该报告，请谨慎操作！！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    phoneNumber: 'warning'
                }).then(() => {   //确定走这里提示


                    //ajax发送要删除的id给后台
                    axios.get("/medical/delete.do?id=" + row.id).then((response) => {
                        if (response.data.flag) {
                            //表示删除成功
                            this.$message.success(response.data.message)
                            //删除后要重新执行一次查询操作,更新页面数据
                            this.findPage();
                        } else {
                            //表示删除失败
                            this.$message.error({
                                message: response.data.message   //这是来自后台的提示信息
                            })
                        }
                    }).catch((response) => {
                        this.showMessage(response)
                    });


                }).catch(() => {
                    this.$message({   //取消这里提示
                        phoneNumber: 'info',
                        message: '已取消删除'
                    });
                });

            },


        }
    })
</script>
</html>